<?php
/**
 *数据库备份类
 *@author sulwan@126.com
 *@date 2009-11-20
 */

 class Data extends Application{
        public $Classlist;

 public function __construct() {
        parent::__construct();
 }

 public function showTable() {
        $sql = 'SHOW TABLE STATUS';
        return $this->_db->getAll($sql);
 }


public function dropTable($table) {
        $sql = 'SHOW CREATE TABLE '.$table;
        return $this->_db->getFetch($sql);
}


public function tableRow($table,$startfrom, $pagesize) {
        $sql = "SELECT * FROM $table LIMIT $startfrom, $pagesize";
        return $this->_db->getAll_Num($sql);
}


public function num_fields($table,$startfrom, $pagesize) {
        $sql = "SELECT * FROM $table LIMIT $startfrom, $pagesize";
        return $this->_db-> num_fields($sql);
}


public function num_rows($table,$startfrom, $pagesize) {
        $sql = "SELECT * FROM $table LIMIT $startfrom, $pagesize";
        return $this->_db-> num_rows($sql);
}


public function tableQuery($sql) {
        $this->sql_execute($sql);
}



public function sql_execute($sql) {
	$sqls = $this -> sql_split($sql);
	if (is_array($sqls)) {
		foreach($sqls as $sql) {
			if (trim($sql) != '') {
				$this ->_db->execute($sql);
			}
		}
	} else {
		$this ->_db->execute($sqls);
	}
	return true;
}

public function sql_split($sql) {
    global $config;
	if ($this->_db -> version() > '4.1' && $config['code']) {
		$sql = preg_replace("/TYPE=(InnoDB|MyISAM)( DEFAULT CHARSET=[^; ]+)?/", "TYPE=\\1 DEFAULT CHARSET=" . $config['code'], $sql);
	}
	$sql = str_replace("\r", "\n", $sql);
	$ret = array();
	$num = 0;
	$queriesarray = explode(";\n", trim($sql));
	unset($sql);
	foreach($queriesarray as $query) {
		$ret[$num] = '';
		$queries = explode("\n", trim($query));
		$queries = array_filter($queries);
		foreach($queries as $query) {
			$str1 = substr($query, 0, 1);
			if ($str1 != '#' && $str1 != '-') $ret[$num] .= $query;
		}
		$num++;
	}
	return($ret);
}





 }
?>